#ifndef _SOCKETADDRESSIMPL_HPP_
#define _SOCKETADDRESSIMPL_HPP_

#include "types.hpp"
#include "jhdefs.hpp"
#include "net/SocketDefs.hpp"
#include "net/IPAddress.hpp"
NET_NAMESPACE_BEGIN

class CSocketAddressImpl
{
public:
	virtual ~CSocketAddressImpl();
	virtual CIPAddress host() const = 0;
	virtual UInt16 port() const = 0;
	virtual JH_SOCKETLEN length() const = 0;
	virtual const struct sockaddr* addr() const = 0;
	virtual int af() const = 0;

protected:
	CSocketAddressImpl();

private:
	CSocketAddressImpl(const CSocketAddressImpl&);
	CSocketAddressImpl& operator = (const CSocketAddressImpl&);
};


class CIPv4SocketAddressImpl : public CSocketAddressImpl
{
public:
	CIPv4SocketAddressImpl();
	CIPv4SocketAddressImpl(const struct sockaddr_in* addr);
	CIPv4SocketAddressImpl(const void* addr, UInt16 port);
	CIPAddress host() const;
	UInt16 port() const;
	JH_SOCKETLEN length() const;
	const struct sockaddr* addr() const;
	int af() const;

private:
	struct sockaddr_in m_addr;
};


#ifdef JH_HAVE_IPv6
class CIPv6SocketAddressImpl : public CSocketAddressImpl
{
public:
	CIPv6SocketAddressImpl(const struct sockaddr_in6* addr);
	CIPv6SocketAddressImpl(const void* addr, UInt16 port);
	CIPv6SocketAddressImpl(const void* addr, UInt16 port, UInt32 scope);
	CIPAddress host() const;
	UInt16 port() const;
	JH_SOCKETLEN length() const;
	const struct sockaddr* addr() const;
	int af() const;
private:
	struct sockaddr_in6 m_addr;
};
#endif

NET_NAMESPACE_END

#endif
